package com.storage.system.service.impl;

import java.util.List;

import com.storage.common.core.domain.ServiceResponse;
import com.storage.common.core.page.TableDataInfo;
import com.storage.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.storage.system.mapper.StorageIndustryMapper;
import com.storage.system.domain.StorageIndustry;
import com.storage.system.service.IStorageIndustryService;
import com.storage.common.core.text.Convert;

/**
 * 行业类型Service业务层处理
 *
 * @author ruoyi
 * @date 2019-10-31
 */
@Service
public class StorageIndustryServiceImpl implements IStorageIndustryService {

    @Autowired
    private StorageIndustryMapper storageIndustryMapper;

    /**
     * 查询行业类型
     *
     * @param id 行业类型ID
     * @return 行业类型
     */
    @Override
    public StorageIndustry selectStorageIndustryById(Long id) {
        return storageIndustryMapper.selectStorageIndustryById(id);
    }

    /**
     * 查询行业类型列表
     *
     * @param storageIndustry 行业类型
     * @return 行业类型
     */
    @Override
    public ServiceResponse<TableDataInfo> selectStorageIndustryList(StorageIndustry storageIndustry, Integer pageNum, Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 10;
        }

        Integer start = (pageNum - 1) * pageSize;
        // 查询查询分页数据
        List<StorageIndustry> messages = storageIndustryMapper.queryPageList(storageIndustry, start, pageSize);
        // 查询totalCount
        Long totalCount = storageIndustryMapper.queryPageCount(storageIndustry);

        TableDataInfo pageList = new TableDataInfo(messages, totalCount, pageNum, pageSize);
        return new ServiceResponse<>(true, pageList, null);
    }

    /**
     * 查询行业类型列表
     *
     * @param storageIndustry 行业类型
     * @return 行业类型
     */
    @Override
    public ServiceResponse<List<StorageIndustry>> selectStorageIndustryList(StorageIndustry storageIndustry) {
        List<StorageIndustry> list = storageIndustryMapper.selectStorageIndustryList(storageIndustry);
        return new ServiceResponse<>(true, list, null);
    }


    /**
     * 新增行业类型
     *
     * @param storageIndustry 行业类型
     * @return 结果
     */
    @Override
    public int insertStorageIndustry(StorageIndustry storageIndustry) {
        storageIndustry.setCreateTime(DateUtils.getNowDate());
        return storageIndustryMapper.insertStorageIndustry(storageIndustry);
    }

    /**
     * 修改行业类型
     *
     * @param storageIndustry 行业类型
     * @return 结果
     */
    @Override
    public ServiceResponse<StorageIndustry> updateStorageIndustry(StorageIndustry storageIndustry) {
        if (storageIndustry.getId() == null) {
            storageIndustryMapper.insertStorageIndustry(storageIndustry);
        }
        storageIndustryMapper.updateStorageIndustry(storageIndustry);
        return new ServiceResponse<>(true, storageIndustryMapper.selectStorageIndustryById(storageIndustry.getId()), null);
    }

    /**
     * 删除行业类型对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteStorageIndustryByIds(String ids) {
        return storageIndustryMapper.deleteStorageIndustryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除行业类型信息
     *
     * @param id 行业类型ID
     * @return 结果
     */
    @Override
    public int deleteStorageIndustryById(Long id) {
        return storageIndustryMapper.deleteStorageIndustryById(id);
    }
}
